//
//  ShapeCache.swift
//  PrototypePattern
//
//  Created by 好米有易 on 2017/12/14.
//  Copyright © 2017年 好米有易. All rights reserved.
//

import UIKit

class ShapeCache {

  static var shapeMap:[String: Shap]  = [:]
    
  public static func getShape(shapeId: String) -> Shap {
        
        guard let cachedShape: Shap = shapeMap[shapeId] else { return Circle()}

        
    return cachedShape.clone() as! Shap
        
    }
    
    
   public static func loadCache() {
        
        let circle = Circle()
        circle.setId(id: "1")
        shapeMap[circle.getId()] = circle
        
        let rectangle = Rectangle()
        rectangle.setId(id: "2")
        shapeMap[rectangle.getId()] = rectangle
        
        let square = Square()
        square.setId(id: "3")
        shapeMap[square.getId()] = square
        
    }
    
}
